package com.example.demo.config;

import javax.servlet.MultipartConfigElement;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * @ClassName TomcatConfig
 * @Description
 * @Author 51
 * @Date 2019年11月28日 下午7:13:20
 */
@SuppressWarnings("deprecation")
//@Configuration
public class TomcatConfig {
    @Autowired
    private Environment environment;

    /**
     * 文件上传临时路径
     */
    @Bean
    MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        String kString = Thread.currentThread().getContextClassLoader().getResource("").getFile();
        factory.setLocation(kString);
        //factory.setLocation(environment.getProperty("server.tomcat.basedir"));
        return factory.createMultipartConfig();
    }

}